{"ast":null,"code":"var __values = this && this.__values || function (o) {\n  var s = typeof Symbol === \"function\" && Symbol.iterator,\n    m = s && o[s],\n    i = 0;\n  if (m) return m.call(o);\n  if (o && typeof o.length === \"number\") return {\n    next: function () {\n      if (o && i >= o.length) o = void 0;\n      return {\n        value: o && o[i++],\n        done: !o\n      };\n    }\n  };\n  throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n};\nimport { CLEANUP_TIMER_LOOP_MILLIS, createTrackingData } from \"./reactionCleanupTrackingCommon\";\n/**\n * timers, gc-style, uncommitted reaction cleanup\n */\nexport function createTimerBasedReactionCleanupTracking() {\n  /**\n   * Reactions created by components that have yet to be fully mounted.\n   */\n  var uncommittedReactionRefs = new Set();\n  /**\n   * Latest 'uncommitted reactions' cleanup timer handle.\n   */\n  var reactionCleanupHandle;\n  /* istanbul ignore next */\n  /**\n   * Only to be used by test functions; do not export outside of mobx-react-lite\n   */\n  function forceCleanupTimerToRunNowForTests() {\n    // This allows us to control the execution of the cleanup timer\n    // to force it to run at awkward times in unit tests.\n    if (reactionCleanupHandle) {\n      clearTimeout(reactionCleanupHandle);\n      cleanUncommittedReactions();\n    }\n  }\n  /* istanbul ignore next */\n  function resetCleanupScheduleForTests() {\n    var e_1, _a;\n    if (uncommittedReactionRefs.size > 0) {\n      try {\n        for (var uncommittedReactionRefs_1 = __values(uncommittedReactionRefs), uncommittedReactionRefs_1_1 = uncommittedReactionRefs_1.next(); !uncommittedReactionRefs_1_1.done; uncommittedReactionRefs_1_1 = uncommittedReactionRefs_1.next()) {\n          var ref = uncommittedReactionRefs_1_1.value;\n          var tracking = ref.current;\n          if (tracking) {\n            tracking.reaction.dispose();\n            ref.current = null;\n          }\n        }\n      } catch (e_1_1) {\n        e_1 = {\n          error: e_1_1\n        };\n      } finally {\n        try {\n          if (uncommittedReactionRefs_1_1 && !uncommittedReactionRefs_1_1.done && (_a = uncommittedReactionRefs_1.return)) _a.call(uncommittedReactionRefs_1);\n        } finally {\n          if (e_1) throw e_1.error;\n        }\n      }\n      uncommittedReactionRefs.clear();\n    }\n    if (reactionCleanupHandle) {\n      clearTimeout(reactionCleanupHandle);\n      reactionCleanupHandle = undefined;\n    }\n  }\n  function ensureCleanupTimerRunning() {\n    if (reactionCleanupHandle === undefined) {\n      reactionCleanupHandle = setTimeout(cleanUncommittedReactions, CLEANUP_TIMER_LOOP_MILLIS);\n    }\n  }\n  function scheduleCleanupOfReactionIfLeaked(ref) {\n    uncommittedReactionRefs.add(ref);\n    ensureCleanupTimerRunning();\n  }\n  function recordReactionAsCommitted(reactionRef) {\n    uncommittedReactionRefs.delete(reactionRef);\n  }\n  /**\n   * Run by the cleanup timer to dispose any outstanding reactions\n   */\n  function cleanUncommittedReactions() {\n    reactionCleanupHandle = undefined;\n    // Loop through all the candidate leaked reactions; those older\n    // than CLEANUP_LEAKED_REACTIONS_AFTER_MILLIS get tidied.\n    var now = Date.now();\n    uncommittedReactionRefs.forEach(function (ref) {\n      var tracking = ref.current;\n      if (tracking) {\n        if (now >= tracking.cleanAt) {\n          // It's time to tidy up this leaked reaction.\n          tracking.reaction.dispose();\n          ref.current = null;\n          uncommittedReactionRefs.delete(ref);\n        }\n      }\n    });\n    if (uncommittedReactionRefs.size > 0) {\n      // We've just finished a round of cleanups but there are still\n      // some leak candidates outstanding.\n      ensureCleanupTimerRunning();\n    }\n  }\n  return {\n    addReactionToTrack: function (reactionTrackingRef, reaction,\n    /**\n     * On timer based implementation we don't really need this object,\n     * but we keep the same api\n     */\n    objectRetainedByReact) {\n      reactionTrackingRef.current = createTrackingData(reaction);\n      scheduleCleanupOfReactionIfLeaked(reactionTrackingRef);\n      return reactionTrackingRef.current;\n    },\n    recordReactionAsCommitted: recordReactionAsCommitted,\n    forceCleanupTimerToRunNowForTests: forceCleanupTimerToRunNowForTests,\n    resetCleanupScheduleForTests: resetCleanupScheduleForTests\n  };\n}","map":{"version":3,"mappings":";;;;;;;;;;;;;;;;AACA,SAGIA,yBAAyB,EACzBC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AAMf,QAAQ,GAAGD,GAAG,CAACE,OAAO;MAC5B,IAAID,QAAQ,EAAE;QACV,IAAIa,GAAG,IAAIb,QAAQ,CAACgB,OAAO,EAAE;UACzB;UACAhB,QAAQ,CAACE,QAAQ,CAACC,OAAO,EAAE;UAC3BJ,GAAG,CAACE,OAAO,GAAG,IAAI;UAClBV,uBAAuB,CAACqB,MAAM,CAACb,GAAG,CAAC;;;IAG/C,CAAC,CAAC;IAEF,IAAIR,uBAAuB,CAACO,IAAI,GAAG,CAAC,EAAE;MAClC;MACA;MACAQ,yBAAyB,EAAE;;EAEnC;EAEA,OAAO;IACHW,kBAAkB,EAAlB,UACIC,mBAAqE,EACrEhB,QAAkB;IAClB;;;;IAIAiB,qBAA8B;MAE9BD,mBAAmB,CAACjB,OAAO,GAAGZ,kBAAkB,CAACa,QAAQ,CAAC;MAC1DM,iCAAiC,CAACU,mBAAmB,CAAC;MACtD,OAAOA,mBAAmB,CAACjB,OAAO;IACtC,CAAC;IACDS,yBAAyB;IACzBhB,iCAAiC;IACjCG,4BAA4B;GAC/B;AACL","names":["CLEANUP_TIMER_LOOP_MILLIS","createTrackingData","createTimerBasedReactionCleanupTracking","uncommittedReactionRefs","Set","reactionCleanupHandle","forceCleanupTimerToRunNowForTests","clearTimeout","cleanUncommittedReactions","resetCleanupScheduleForTests","size","ref","tracking","current","reaction","dispose","clear","undefined","ensureCleanupTimerRunning","setTimeout","scheduleCleanupOfReactionIfLeaked","add","recordReactionAsCommitted","reactionRef","delete","now","Date","forEach","cleanAt","addReactionToTrack","reactionTrackingRef","objectRetainedByReact"],"sources":["/data/messenger.client/node_modules/mobx-react-lite/src/utils/createTimerBasedReactionCleanupTracking.ts"],"sourcesContent":["import { Reaction } from \"mobx\"\nimport {\n    ReactionCleanupTracking,\n    IReactionTracking,\n    CLEANUP_TIMER_LOOP_MILLIS,\n    createTrackingData\n} from \"./reactionCleanupTrackingCommon\"\n\n/**\n * timers, gc-style, uncommitted reaction cleanup\n */\nexport function createTimerBasedReactionCleanupTracking(): ReactionCleanupTracking {\n    /**\n     * Reactions created by components that have yet to be fully mounted.\n     */\n    const uncommittedReactionRefs: Set<React.MutableRefObject<IReactionTracking | null>> = new Set()\n\n    /**\n     * Latest 'uncommitted reactions' cleanup timer handle.\n     */\n    let reactionCleanupHandle: ReturnType<typeof setTimeout> | undefined\n\n    /* istanbul ignore next */\n    /**\n     * Only to be used by test functions; do not export outside of mobx-react-lite\n     */\n    function forceCleanupTimerToRunNowForTests() {\n        // This allows us to control the execution of the cleanup timer\n        // to force it to run at awkward times in unit tests.\n        if (reactionCleanupHandle) {\n            clearTimeout(reactionCleanupHandle)\n            cleanUncommittedReactions()\n        }\n    }\n\n    /* istanbul ignore next */\n    function resetCleanupScheduleForTests() {\n        if (uncommittedReactionRefs.size > 0) {\n            for (const ref of uncommittedReactionRefs) {\n                const tracking = ref.current\n                if (tracking) {\n                    tracking.reaction.dispose()\n                    ref.current = null\n                }\n            }\n            uncommittedReactionRefs.clear()\n        }\n\n        if (reactionCleanupHandle) {\n            clearTimeout(reactionCleanupHandle)\n            reactionCleanupHandle = undefined\n        }\n    }\n\n    function ensureCleanupTimerRunning() {\n        if (reactionCleanupHandle === undefined) {\n            reactionCleanupHandle = setTimeout(cleanUncommittedReactions, CLEANUP_TIMER_LOOP_MILLIS)\n        }\n    }\n\n    function scheduleCleanupOfReactionIfLeaked(\n        ref: React.MutableRefObject<IReactionTracking | null>\n    ) {\n        uncommittedReactionRefs.add(ref)\n\n        ensureCleanupTimerRunning()\n    }\n\n    function recordReactionAsCommitted(\n        reactionRef: React.MutableRefObject<IReactionTracking | null>\n    ) {\n        uncommittedReactionRefs.delete(reactionRef)\n    }\n\n    /**\n     * Run by the cleanup timer to dispose any outstanding reactions\n     */\n    function cleanUncommittedReactions() {\n        reactionCleanupHandle = undefined\n\n        // Loop through all the candidate leaked reactions; those older\n        // than CLEANUP_LEAKED_REACTIONS_AFTER_MILLIS get tidied.\n\n        const now = Date.now()\n        uncommittedReactionRefs.forEach(ref => {\n            const tracking = ref.current\n            if (tracking) {\n                if (now >= tracking.cleanAt) {\n                    // It's time to tidy up this leaked reaction.\n                    tracking.reaction.dispose()\n                    ref.current = null\n                    uncommittedReactionRefs.delete(ref)\n                }\n            }\n        })\n\n        if (uncommittedReactionRefs.size > 0) {\n            // We've just finished a round of cleanups but there are still\n            // some leak candidates outstanding.\n            ensureCleanupTimerRunning()\n        }\n    }\n\n    return {\n        addReactionToTrack(\n            reactionTrackingRef: React.MutableRefObject<IReactionTracking | null>,\n            reaction: Reaction,\n            /**\n             * On timer based implementation we don't really need this object,\n             * but we keep the same api\n             */\n            objectRetainedByReact: unknown\n        ) {\n            reactionTrackingRef.current = createTrackingData(reaction)\n            scheduleCleanupOfReactionIfLeaked(reactionTrackingRef)\n            return reactionTrackingRef.current\n        },\n        recordReactionAsCommitted,\n        forceCleanupTimerToRunNowForTests,\n        resetCleanupScheduleForTests\n    }\n}\n"]},"metadata":{},"sourceType":"module"}